<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2020/6/22
 * Time: 20:20
 */

namespace App\HttpController\V1;


use App\Services\HelpService;
use App\Services\ReponseCodeService;
use App\Services\UserService;

class Auth extends ApiController
{
    /**
     * showdoc
     * @catalog 开放平台
     * @title  获取授权token
     * @description 获取授权token,token用于socket连接服务
     * @method  GET
     * @url /v1/auth
     * @param  nonce  是 string 消息随机字符串，由时间戳+6位随机字符串，用于消息校验,提交之前请加密
     * @param  content  是 string 除了timestamp，nonce,content,sign,access_key这是5参数，其他参数都是包裹在content，并进行aes加密
     * @param  timestamp  是 string 时间戳
     * @param  sign  是 string 签名，生成规则$content.$timestamp.$nonce，注意，这时候的nonce没有加密
     * @param  access_key 是 string 应用access_key
     * @return_param  code int 状态码(200:成功0:失败400:参数错误)
     * @return_param  token string 用于socket连接服务
     * @remark 下发的数据也是加密的，每次断线请重新请求获取新的token。
     */
    public function getToken(){
        $app = $this->app;
        $userService = new UserService();
        $login = $userService->login($app['user_id']);
        $returnData['token'] = $login['token'];
        return  $this->writeJson(ReponseCodeService::CODE_OK,  HelpService::aesEncrypt(json_encode($returnData),$this->app['access_key'],$this->app['secret_key']), "sucess");
    }
}